<?php
include_once("admin.inc.php");
$act = get_param('action');
$advModel = load_model("advertise");

switch($act):
case 'list1':
	$list = $advModel->get_list();
	$smarty->assign('list',$list);
	$smarty->assign('type',1);
	$smarty->assign('title','首页广告大图');
	$smarty->display('admin/advertise.html');
break;
case 'list2':
	$list = $advModel->get_list("",2);
	$smarty->assign('list',$list);
	$smarty->assign('type',2);
	$smarty->assign('title','滚动广告图');
	$smarty->display('admin/advertise.html');
break;
case 'addAdv':
	$data = get_data();
	unset($data['id']);
	$up = load_class('Upload');
	$up->config(array('save_path'=>__UPLOAD__.'images/adv/','safe_ext'=>array('jpg','jpeg','gif','png')));
	$rs = $up->save();
	if( !$rs ){
		msg("上传图片失败。".$up->get('error'));
		exit;
	}
	$data['file_name'] = $up->saveName;
	$rs = $advModel->add_adv($data);
	if( $rs ){
		msg('Success','advertise.php?action=list'.$data['type']);
	}else{
		msg("添加失败。".$advModel->get_error());
	}
break;
case 'editAdv':
	$data = get_data();
	if( !empty($_FILES['file']['tmp_name']) ){
		$up = load_class('Upload');
		$up->config(array('save_path'=>__UPLOAD__.'images/adv/','safe_ext'=>array('jpg','jpeg','gif','png')));
		$rs = $up->save();
		if( !$rs ){
			msg("上传图片失败。".$up->get('error'));
			exit;
		}
		$data['file_name'] = $up->saveName;
	}
	$rs = $advModel->edit_adv($data['id'], $data);
	if( $rs ){
		msg('Success','advertise.php?action=list'.$data['type']);
	}else{
		msg('Failed','advertise.php?action=list'.$data['type']);
	}
break;
case 'delAdv':
	$id = get_param('id');
	$type = get_param('type');
	$rs = $advModel->del_adv($id);
	if( $rs ){
		msg('Success','advertise.php?action=list'.$type);
	}else{
		msg('Failed','advertise.php?action=list'.$type);
	}
break;
endswitch;
